package designpattern.strategy.now.discount;

import java.text.MessageFormat;

/**
 * @author zhaoqiankun
 * @since 2021-12-27 1:04
 * 类 BuyGoods，维护了⼀个 AbstractDiscount 引⽤
 */
public class BuyGoods {
    private String goods;
    private double price;
    private AbstractDiscount abstractDiscount;

    public BuyGoods(String goods, double price, AbstractDiscount
            abstractDiscount) {
        this.goods = goods;
        this.price = price;
        this.abstractDiscount = abstractDiscount;
    }

    /**
     * 根据类型获取价格
     * @return
     */
    public double calculate() {
        double finalPrice = abstractDiscount.discount(this.price);
        String desc = abstractDiscount.getDesc();
        System.out.println(MessageFormat.format("商品：{0}，原价：{1}，{2}，最 终价格为：{3}"
                , goods, price, desc, finalPrice));
        return finalPrice;
    }
}
